package server.business.chat.handler;

import com.core.initialize.Message;
import com.google.protobuf.GeneratedMessage;

import server.ServerHandler;
import server.ServerTransportProxy;
import server.commonData.Information;
import server.commonData.Room;
import server.commonData.User;
import server.messageId.S2CMessageId;
import server.msgBean.ChatMessage.ChatReq;
import server.msgBean.ChatMessage.ChatRes;
/**
 * 全服务器聊天
 * @author King
 *
 */
public class WorldChatHandler extends ServerHandler {

	@Override
	public Class<? extends GeneratedMessage> initBodyClass()
	{
		return ChatReq.class;
	}

	@Override
	protected void handler(Message msg, User user) throws Throwable
	{
		if(user==null)
			return;
		if(user.isShutup())
		{
			Information info = Information.newInformation(3);
			ServerTransportProxy.sendMsg(info.toMessage(), user);
			return;
		}
		Room room = user.getRoom();
		if(room==null)
			return;
		ChatReq req = msg.getBody();
		//TODO 消耗一些东西 看需求
		
		ChatRes.Builder builder = ChatRes.newBuilder();
		builder.setContent(req.getContent());
		builder.setPlayerId(user.getId());
		builder.setPlayerName(user.getName());
		
		msg.clearDate();
		msg.setModuleAction(S2CMessageId.Chat.MODULE_ID,S2CMessageId.Chat.CHAT_TOALL_RES);
		msg.setBody(builder);
		ServerTransportProxy.sendToAll(msg);
	}

}
